#include "utils.h"
#include <string>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <gl/glut.h>


int GetDif(int a, int b)
{
	if (a>b) return a-b;
	else return b-a;
}

double GetDif(double a, double b)
{
	if (a>b) return a-b;
	else return b-a;
}

char * getKeyName(Chords key)
{
	char * toRet;
	switch (key)
	{
		case C: //Red
			toRet = "C";
			break;
		case G: //Pink
			toRet = "G";
			break;
		case D: //Magenta
			toRet = "D";
			break;
		case A: //Violet
			toRet = "A";
			break;
		case E: //Blue	205 (or 255 for brighter blue)
			toRet = "E";
			break;
		case B: //Dodgerblue
			toRet = "B";
			break;
		case Gb: //Cyan
			toRet = "Gb/F#";
			break;
		case Db: //Spring
			toRet = "Db/C#";
			break;
		case Ab: //Green/lime
			toRet = "Ab/G#";
			break;
		case Eb: //"Lawn" green
			toRet = "Eb/D#";
			break;
		case Bb: //Yellow
			toRet = "Bb/A#";
			break;
		case F: //Orange
			toRet = "F";
			break;
		default: 
			toRet = "??";
			break; 
	}
	return toRet;
}


//-------------------------------------------------------------------------
//  Draws a string at the specified coordinates.
//    From http://mycodelog.com/2010/03/23/printw/
//-------------------------------------------------------------------------
void printw (float x, float y, float z, char* format, ...)
{
    va_list args;   //  Variable argument list
    int len;        // String length
    int i;          //  Iterator
    char * text;    // Text

	GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24;

    //  Initialize a variable argument list
    va_start(args, format);

    //  Return the number of characters in the string referenced the list of arguments.
    // _vscprintf doesn't count terminating '\0' (that's why +1)
    len = _vscprintf(format, args) + 1;

    //  Allocate memory for a string of the specified size
    text = (char *)malloc(len * sizeof(char));

    //  Write formatted output using a pointer to the list of arguments
    vsprintf_s(text, len, format, args);

    //  End using variable argument list
    va_end(args);

    //  Specify the raster position for pixel operations.
    glRasterPos3f (x, y, z);

    //  Draw the characters one by one
    for (i = 0; text[i] != '\0'; i++)
    glutBitmapCharacter(font_style, text[i]);

    //  Free the allocated memory for the string
    free(text);
}


Note::Note()
{
	//
}

Note::Note(Keys k, Chords c, int vol, bool main)
{
	mKey = k;
	mChord = c;
	mVol = vol;
	mMain = main;
}